version 16
quietly{
*use "C:\Users\achen.POL-PF10YAEL\Documents\Word\citizen assemblies\Krashinsky project\BC data\bc 2005.dta"

* USE THIS ONE FOR LAPTOP
*cd "C:\Users\achen.POL-PF10YAEL\Documents\Word\citizen assemblies\Krashinsky project\BC data"

*THIS ONE IS FOR WORK DESKTOP
cd "C:\Users\achen\Documents\Word\citizen assemblies\Krashinsky project\BC data"

*IS THIS THE LOG FILE YOU WANT?  ALSO CHECK LOG CLOSE AT END.
log using bc2005finalrun.txt, replace text

* incumbent Libs had won 77 of 79 seats in 2001, with NDP 2; they won 46 to NDP's
* 33 in 2005. This survey is pre-election 2005.  

gen weight = bcwgt
clonevar femaleorig = rgender
gen female = 1
replace female = 0 if femaleorig!=5
replace female = . if femaleorig==.

clonevar choicereforig = v4
gen choiceref = choicereforig
replace choiceref = 0 if choicereforig == 5
replace choiceref = . if choicereforig>5
label define choiceref 0 "no" 1 "yes"
label values choiceref choiceref

*Next variable is intended vote in 2005.  
* Eventual 2005 votes were 45.8 Lib, 41.5 NDP, 9.2 Green, rest each < 1
clonevar choiceprovorig = v2
gen choiceprov = choiceprovorig
replace choiceprov = . if choiceprovorig>3
replace choiceprov = 4 if choiceprovorig==8
label define choiceprov 1 "Liberals" 2 "NDP" 3 "Greens" 4 "DK"
label values choiceprov choiceprov

gen libchoice = 0
replace libchoice = 1 if v2==1
gen ndpchoice = 0
replace ndpchoice = 1 if v2==2
gen greenchoice = 0
replace greenchoice = 1 if v2==3
gen DKchoice = 0
replace DKchoice = 1 if v2==4

*Correct answer on next one is yes=1; DK and refused coded as wrong answer throughout;
* some items correct = 5:
gen refinfo1 = 1
replace refinfo1 = 0 if a3 != 1
*Note error in codebook on codes for the following one:
gen refinfo2 = 0
replace refinfo2 = 1 if a5a == 2
replace refinfo2 = 1 if a5b == 1
gen refinfo3 = 1
replace refinfo3 = 0 if b2!=1
gen refinfo4 = 1
replace refinfo4 = 0 if b3!=5
gen refinfo5 = 1
replace refinfo5 = 0 if b5!=1
*"almost all" and "most" counted as true in following:
gen refinfo6 =1
replace refinfo6 = 0 if b8>2
gen refinfo = (refinfo1 + refinfo2 + refinfo3 + refinfo4 + refinfo5 + refinfo6)/6
*This one is for comparison with 2009 survey:
gen refinfocomp05 = refinfo1 + refinfo2 + refinfo3 + refinfo4 + refinfo5 + refinfo6
*Next one is for comparison with Ontario survey (identical questions):
gen refinfoshort = (refinfo1 + refinfo2 + refinfo3)/3

clonevar votereflikelyorig = v3
gen votereflikely = votereflikelyorig
*code DK, refused as very unlikely; need to reverse scale, too:
replace votereflikely = 4 if votereflikelyorig>4
replace votereflikely = 1 - (votereflikely - 1)/3
clonevar refinterestorig = d2
gen refinterest = refinterestorig
*code DK, refused as "no interest" in referendum:
replace refinterest = 0 if refinterestorig>10
replace refinterest = refinterest/10

*Party knowledge questions are dubious due to public silence.  Here Libs are
*coded as anti, NDP as pro, Greens as pro
gen libknow = 1
replace libknow = 0 if e1b != 5
gen ndpknow = 1
replace ndpknow = 0 if e2b != 1
gen greenknow = 1
replace greenknow = 0 if e3b != 1
gen partyknow = (libknow+ndpknow+greenknow)/3

gen libchoiceknow = 0
replace libchoiceknow = 1 if libchoice==1 & libknow==1
gen ndpchoiceknow = 0
replace ndpchoiceknow = 1 if ndpchoice==1 & ndpknow==1
gen greenchoiceknow = 0
replace greenchoiceknow = 1 if greenchoice==1 & greenknow==1
}
tab e1b [aweight=weight]
tab e2b [aweight=weight]
tab e3b [aweight=weight]
quietly {
gen polinfo1 = 1
replace polinfo1 = 0 if f1 != 1
gen polinfo2 = 1
replace polinfo2 = 0 if f2 != 1
gen polinfo3 = 1
replace polinfo3 = 0 if f3 != 1
gen polinfo4 = 1
replace polinfo4 = 0 if f4 != 3
gen polinfo = (polinfo1 + polinfo2 + polinfo3 + polinfo4)/4

gen minorpolinfo = 0
replace minorpolinfo = polinfo*(ndpchoice + greenchoice)
*Now therms in lieu of PIDs, which are missing from survey.
*DK, refused coded as 50 (midpoint):
gen libthermorig = h3
gen libtherm = libthermorig
replace libtherm = 50 if libthermorig > 100
replace libtherm = libtherm/100
gen ndpthermorig = h4
gen ndptherm = ndpthermorig
replace ndptherm = 50 if ndpthermorig > 100
replace ndptherm = ndptherm/100
gen greenthermorig = h5
gen greentherm = greenthermorig
replace greentherm = 50 if greenthermorig > 100
replace greentherm = greentherm/100

*Now some items about values and trust in Cit Assmb, with DK, refused = no:
gen promultiparty = 1
replace promultiparty = 0 if c1a!= 1 & c1b!=2
gen proproportionality = 1
replace proproportionality = 0 if c2!=5
gen prochoices = 1
replace prochoices = 0 if c5a !=2 & c5b!=1
gen proprefs = (promultiparty + proproportionality + prochoices)/3
gen trustcitassmb = 1
replace trustcitassmb = 0 if j1!=1

gen dob = dm1
gen age = 2005 - dob
replace age = . if dob>9990
replace age = age/82
gen educorig = dm2
gen educ = educorig
replace educ = . if educorig>10
replace educ = educ/10
gen immigrant = 1
replace immigrant = 0 if dm3==1
gen churchattendorig = dm8
gen churchattend = churchattendorig
*code DK, refused as "never"
replace churchattend = 5 if churchattendorig>5
replace churchattend = 1 - (churchattend - 1)/4
gen incomeorig = dm11
gen income = incomeorig
replace income = 200 if incomeorig>200
replace income = . if incomeorig>997
gen incmissing = 0
replace incmissing = 1 if income==.
replace income = 0 if income==.
replace income = income/200

clonevar incomesuppl = dm11e
*Omit following: too much missing data in incomesuppl
/*
replace income = 10 if incomesuppl == 1
replace income = 25 if incomesuppl == 2
replace income = 35 if incomesuppl == 3
replace income = 45 if incomesuppl == 4
replace income = 55 if incomesuppl == 5
replace income = 65 if incomesuppl == 6
replace income = 75 if incomesuppl == 7
replace income = 85 if incomesuppl == 8
replace income = 95 if incomesuppl == 9
replace income = 110 if incomesuppl == 10
replace income = 135 if incomesuppl == 11
replace income = 200 if incomesuppl == 12
*/

}
tab choiceref choiceprov [aweight=weight], col
tab choiceref refinfo  [aweight=weight], col
*Find N's for previous one:
tab choiceref refinfo , col
tab choiceref polinfo  [aweight=weight], col
*Now for N's on previous one:
tab choiceref polinfo , col
tab choiceref proprefs [aweight=weight], col
tab choiceref trustcitassm [aweight=weight], col

tab trustcitassmb polinfo [aweight=weight] , col
bysort choiceprov: tab trustcitassmb polinfo [aweight=weight] , col

tab choiceref choiceprov [aweight=weight], col
tab choiceref choiceprov [aweight=weight] if polinfo==1, col

/*
probit choiceref educ age libchoice ndpchoice greenchoice [pweight=weight]
fitstat
probit choiceref educ age libchoice ndpchoice greenchoice polinfo [pweight=weight]
fitstat
probit choiceref educ age libchoice ndpchoice greenchoice libchoiceknow ndpchoiceknow greenchoiceknow polinfo [pweight=weight]
fitstat
*/ 

probit choiceref i.libchoice i.ndpchoice i.greenchoice  [pweight=weight]
fitstat
eststo dydx_choiceref1: margins, dydx(*) post
*coefplot, drop(_cons) xline(0) rename(1.ndpchoice = "NDP vote" 1.greenchoice = "Green vote" 1.DKchoice = "don't know vote") title(Marginal Effects on Favoring Electoral Change) subti(BC 2005)
*graph export fig5.pdf,  logo(off) replace

*Key run: 
probit choiceref educ age i.libchoice i.ndpchoice i.greenchoice  polinfo minorpolinfo  [pweight=weight]
fitstat
eststo dydx_choiceref2: margins, dydx(*) post

*Check garbage demographics:

probit choiceref educ age i.libchoice i.ndpchoice i.greenchoice  polinfo minorpolinfo i.female income i.incmissing [pweight=weight]
fitstat
eststo dydx_choiceref2: margins, dydx(*) post

probit choiceref educ age i.libchoice i.ndpchoice i.greenchoice  polinfo minorpolinfo i.female income i.incmissing i.incmissing i.immigrant churchattend [pweight=weight]
fitstat
eststo dydx_choiceref2: margins, dydx(*) post
*coefplot, drop(_cons) xline(0) rename(1.ndpchoice = "NDP vote" 1.DKchoice = "don't know vote" 1.greenchoice = "Green vote" polinfo = "political information" educ = "education" 1.female = "female" 1.incmissing = "income missing" 1.immigrant = "immigrant" churchattend = "religious attendance") title(Marginal Effects on Favoring Electoral Change) subti(BC 2005) title(Marginal Effects on Favoring Electoral Change) subti(BC 2007)
*graph export fig6.pdf,  logo(off) replace

* GRAPHS
graph bar (mean) choiceref [aweight = weight], over(choiceprov) ytitle(fraction yes) ti(Referendum Yes Vote by Provincial Vote: BC 2005)
graph export fig1.pdf,  logo(off) replace
graph save fig1, replace

*For line plot:
tab choiceref refinfocomp05 [aweight=weight], col

log close